using UnityEngine;
using System;
using System.Collections;
using LogicalComponent.util;


public class ClickMoveClickHandler : MonoBehaviour, UiUtil.ClickHandler {

    public Pawn MovablePawn;

    public void HandleClick(RaycastHit hit)
    {
        GameObject managerObject = GameObject.FindGameObjectWithTag("game_manager");
        GameManager manager = managerObject.GetComponent<GameManager>();

        if(hit.transform.tag != "pawn")
        {
            Grid grid = manager.grid;
            Coordinate c = grid.GetClickCoordinate(hit);

            if(c != null)
            {
                Debug.Log (String.Format("Moving to {0}", c));

                MovablePawn.SendMessage("SetDestination", c);
            }
        }
        else
        {
            MovablePawn = hit.transform.gameObject.GetComponent<Pawn>();
            Debug.Log("Pawn Clicked");
        }
    }
}
